<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="/lib/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="/lib/layui/css/modules/laydate/default/laydate.css"  media="all">
    <link rel="stylesheet" href="/lib/layui/css/modules/layer/default/layer.css"  media="all">
</head>
<body>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="return">还书</a>
            <a class="layui-btn layui-btn-warm layui-btn-xs data-count-edit" lay-event="renew">续借</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs data-count-edit" lay-event="push">催还</a>
        </script>

    </div>
</div>
<script>
    layui.use(['form', 'table','miniPage','element','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage,
            laydate = layui.laydate;
        form.render();
        table.render({
            initSort: {field:'flag', type:'asc'},
            elem: '#currentTableId',
            url: '/adminBorrowInfo',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                    {field: 'id', title: '借阅号', sort: true},
                    {field: 'borrowerId', title: '借阅人编号', sort: true},
                    {field: 'borrowerName', title: '借阅人姓名', sort: true},
                    {field: 'bookId', title: '借阅书登记号', sort: true},
                    {field: 'bookName', title: '借阅书名', sort: true},
                    {field: 'start',title: '借阅日期', sort: true},
                    {field: 'end', title: '预计归还日期', sort: true},
                    {field: 'flag', title: '是否归还', sort: true},
                    {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
                ]
            ],
            limit: 15,
            page: true,
            skin: 'line'
        });


        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {   // 监听添加操作
                var content = miniPage.getHrefContent('/admin/addBook.html');
                var index = layer.open({
                    title: '添加学生',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['85%','75%'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'push') {
                layer.confirm('<div class="layui-inline">\n' +
                    '      <label class="layui-form-label">验证密码</label>\n' +
                    '      <div class="layui-input-inline">\n' +
                    '        <input type="password" name="pwd" id="pwd" lay-verify="required" autocomplete="off" class="layui-input">\n' +
                    '      </div>\n' +
                    '    </div>', function (index) {
                    $.ajax({
                        url: '/push',
                        type:'POST',
                        data:{
                            id:data.id,
                            pwd:document.getElementById('pwd').value
                        },
                        success:function (res){
                            if(res.code==200){
                                layer.close(index);
                                layer.msg("已发送通知邮件");
                            }else {
                                layer.msg(layer.msg(res.msg));
                            }
                        }

                    })
                    return false;
                });
                return false;
            }else if (obj.event === 'update') {
                var content = miniPage.getHrefContent('/updateBook?id='+data.id);
                var index = layer.open({
                    title: data.name,
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['85%','75%'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }else if (obj.event === 'return') {
                layer.confirm('<div class="layui-inline">\n' +
                    '      <label class="layui-form-label">验证密码</label>\n' +
                    '      <div class="layui-input-inline">\n' +
                    '        <input type="password" name="pwd" id="pwd" lay-verify="required" autocomplete="off" class="layui-input">\n' +
                    '      </div>\n' +
                    '    </div>', function (index) {
                    $.ajax({
                        url: '/return',
                        type:'POST',
                        data:{
                            id:data.id,
                            pwd:document.getElementById('pwd').value
                        },
                        success:function (res){
                            if(res.code==200){
                                layer.close(index);
                                layer.msg("还书成功!");
                                table.reload('currentTableId');
                            }else {
                                layer.msg(res.msg);
                            }
                        }

                    })
                    return false;
                });
            }else if (obj.event === 'renew') {
                var content = miniPage.getHrefContent('/renewBook?bookId='+data.bookId);
                var index = layer.open({
                    title: data.name,
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['85%','75%'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
            return false;
        });

    });
</script>
</body>
</html>

